package com.sharedlease.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Laymedown
 */
public class TimeUtil {

    public static String getNowTime(){
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        return formatter.format(date);
    }

    /**
     *
     * @param size
     * @param type : -1--> seconds , 0--> minutes, 1--> hours, 2-->days
     * @return
     */
    public static Date getMaturityTime(int size, int type){
        DateTime parse = DateUtil.parse(DateUtil.now());
        switch (type){
            case -1: return DateUtil.offsetSecond(parse, size);
            case 0: return DateUtil.offsetMinute(parse, size);
            case 1: return DateUtil.offsetHour(parse, size);
            case 2: return DateUtil.offsetDay(parse, size);
            default: return parse;
        }
    }
}
